
<!DOCTYPE html>
<html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<head lang="en">
    <meta charset="UTF-8">
    <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
    <title>添加商品</title>
</head>
<body>
<form id="uploadForm" enctype="multipart/form-data">
    产品名字：<input type="text" name="name"  value="${product.name}"/><br>
    产品价格：<input type="number" name="price"  value="${product.price}"/><br>
    产品描述：<input type="text" name="description"  value="${product.description}"/><br>
    产品图片：<input type="image" name="listimg"  src="upload/${product.img }" width="180" height="150"/><br>
    产品图片:<input type="file" name="img" multiple="multiple"/><br>
    产品类型：<input  type="text" name="ptype" value="${product.ptype}"/>

</form>
<button id="upload">上传文件</button>
</body>
<script type="text/javascript">
    $(function () {
        $("#upload").click(function () {
            var formData = new FormData($('#uploadForm')[0]);
            $.ajax({
                type: 'post',
                url: "UpdateProduct",
                data: formData,
                cache: false,
                processData: false,
                contentType: false,
            }).success(function (data) {
                alert("上传成功");
                window.location.reload()
            }).error(function () {
                alert("上传失败");
            });
        });
    });
</script>
</html>
 
